<!DOCTYPE HTML><html><head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title><? echo $title ?></title>
<? require("lib.php"); ?>
</head>
<body>
<div class="content-box">
    <div class="content-box-header">
        <h3><? echo $title ?></h3>
        <div class="clear"></div>
    </div>
    <div class="content-box-content">
<?
  switch ($do) {
    case "add": add(); break;
	case "update": update($info); break;
	case "delete": delete($id); break;
    default:	show_info($info);
  }
 function show_box($row, $iseditmode, $isadd){ 
	global $id, $userid, $gee, $baseurl, $h, $refund, $sales_order_detail, $cate, $cateid, $country, $province, $city, $county, $customer, $product, $lang, $code_array,$payment_method, $shipment_method, $arrcurrency, $filter, $baseurl,$express_company, $coupon;
	$title=$row['ref_no'].' - '.ROOT_ORDER_DETAIL;
	// 0 未支付 / 1 已支付 / 2.处理中 / 3 寄送中 / 4 已收到  / 8 客户自己取消  / 9 经销商取消
	$status=$code_array['order_status'];
	$tem=$sales_order_detail->get_rows(64,'sales_order_id',$row['id']);
     $refund_info = $refund->get_row($row['ref_no'], 'sales_order_id');
//     print_r($refund_info);
	$iteming='';
	foreach( $tem as $r ){
		$tempro=$product->get_row($r['product_id']);
		$sku=$tempro['sku'];
		$iteming.=$sku.' * '.$r['quantity'];
		$iteming.='<br />';
	}
	$customer_id=$row['customer_id'];
	if($customer_id==0) $customer_name=ROOT_GUEST_ACCOUNT;
	else {
		$customer_array=$customer->get_row($customer_id);
		$customer_name=$customer_array['first_name'].$customer_array['last_name'];
		if($customer_name=='')$customer_name=$customer_array['nickname'];
	}
	
	//$country_name=$country->get_name($row['country'],$lang);
	$province_name=$province->get_name($row['province'],$lang);
	$city_name=$city->get_name($row['city'],$lang);
	$county_name=$county->get_name($row['county'],$lang);
	$currency_code=$arrcurrency[$row['currency_id']]['code'];
	
	// 支付方式 payment_method
	if($row['payment_method_id']==0) $payment_method_name='-';
	else $payment_method_name=$payment_method->get_name($row['payment_method_id'],$lang);

	$shipment_method_name=$shipment_method->get_name($row['shipment_method_id'],$lang);
	echo $h->hidden('userid', $userid);
	echo $h->hidden('id', $row["id"]);
	echo $h->hidden('filter', $filter);
    echo $h->hidden('payment_method_id', $row['payment_method_id']);
    echo $h->hidden('customer_id', $customer_id);
    echo $h->hidden('total_fee', $row['total_price']);

    // express company 物流公司
    $arr_express=array();
    $tem=$express_company->get_rows(128,'is_enabled',1);
    foreach($tem as $val) $arr_express[$val['id']]=$val;
?>
     <script type="text/javascript">
         $(function(){
             var edit_enabled = 0;
             <?if($refund_info['refund_status'] == 2 || !isset($refund_info)){?>
             edit_enabled = 1;
             <?}?>
//         alert(edit_enabled);
             if(!edit_enabled){
//         alert(edit_enabled);
                 $('input').each(function(){
                     $(this).attr('disabled', 'true');
                     $(this).attr('placeholder', '订单未审核');
                 });
                 $('select').attr('disabled', 'true');
             }
         });

     </script>
	<table width="99%" cellspacing="0" cellpadding="3" class="mbox">
		<tr class="th"><td class="thtitle" width="25%" align="right"><? echo $title ?></td><td>&nbsp;</td></tr>
		<tr><td class="l"><?=ROOT_ORDER_REFERENCE_NUMBER?></td><td><? echo $row['ref_no'] ?></td></tr>
		<tr><td class="l"><?=ROOT_CUSTOMER_NAME?></td><td><? echo $customer_name ?></td></tr>
		<tr><td class="l"><?=ROOT_PRODUCT?></td><td><? echo $iteming ?></td></tr>
		<tr><td class="l"><?=ROOT_AMOUNT?></td><td><? echo $currency_code.' '.($row['total_price'] + $row['wallet_amount']); ?></td></tr>

		<?
		// 优惠券折扣 coupon
		if($row['coupon_discount_amount']>0){
			$tem=$coupon->get_row($row['coupon_id']);
			$tem_coupon=$tem['code'];
		?>
		<tr><td class="l"><?=WEB_COUPON_AMOUNT?></td><td><? echo $row['coupon_discount_amount'].' / '.COUPON.': '.$tem_coupon; ?> </td></tr>
		<?}?>
		<?
		// 积分抵扣 point
		if($row['point_discount_amount']>0){
			$tem_point=$row['point_id'];
		?>
		<tr><td class="l"><?=WEB_POINT_AMOUNT?></td><td><? echo $row['point_discount_amount'].' / '.WEB_POINT_AMOUNT.': '.$tem_point; ?> </td></tr>
		<?}?>
        <?
        if($row['fullcut_amount'] > 0){?>
            <tr><td class="l"><?=ROOT_FULLCUT_AMOUNT?></td><td><? echo $row['fullcut_amount']; ?> </td></tr>
        <?}?>

        <tr><td class="l">钱包支付</td><td><?echo $row['wallet_amount']?></td></tr>
		<tr><td class="l"><?=ROOT_EMAIL?></td><td><? echo $row['email'] ?></td></tr>
		<tr><td class="l"><?=ROOT_RECEIVER?></td><td><? echo $row['contact_name'] ?></td></tr>
		<tr><td class="l"><?=ROOT_RECEIVER_ADDRESS?></td><td><? echo $province_name.$city_name.$county_name.' '.$row['address'].', '.$row['zip'] ?></td></tr>
		<? $nada=''; if(SITE_HAS_INVOICE==0) $nada=' hide '; ?>
		<tr class="<?=$nada?>"><td class="l"><?=ROOT_INVOICE_TO?></td><td><? echo d($row['invoice_header']); ?></td></tr>
		<tr><td class="l"><?=ROOT_PHONE?></td><td><? echo $row['mobile'] ?></td></tr>
		<tr><td class="l"><?=ROOT_CUSTOMER_REMARKS?></td><td><? echo d($row['customer_remark']); ?></td></tr>
		<tr><td class="l"><?=ROOT_ORDER_TIME?></td><td><? echo $row['created_time'] ?></td></tr>

		<tr><td class="l"><?=ROOT_PAYMENT_METHOD?></td><td><? echo $payment_method_name ?></td></tr>
		<? if($row['payment_method_id']==5 || $row['payment_method_id']==6) { ?>
		<tr><td class="l"><?=ROOT_PAID_TIME?></td><td><? echo $h->text('paid_time', $row["paid_time"], 'g') ?></td></tr>
		<tr><td class="l"><?=ROOT_PAYER?></td><td><? echo $h->text('payer', $row["payer"], 'g') ?></td></tr>
		<tr><td class="l"><?=ROOT_PAYER_ID?></td><td><? echo $h->text('payer_id', $row["payer_id"], 'g') ?></td></tr>
		<tr><td class="l"><?=ROOT_PAYMENT_REF_NO?></td><td><? echo $h->text('payment_ref_no', $row["payment_ref_no"], 'g') ?></td></tr>
		<tr><td class="l"><?=ROOT_PICTURE?></td><td>
            <? if(! is_null($row['receipt_doc'])) echo '<a href="../upload/'.$row['receipt_doc'].'" target="_blank"><img src="'.$baseurl.'upload/'.decode($row["receipt_doc"]).'" height="80" /></a><br />'; ?>
            <? echo $h->cfile('cpic', 'g') ?>
        </td></tr>
		<? }else { ?>
		<tr><td class="l"><?=ROOT_PAID_TIME?></td><td><? echo $row['paid_time'] ?></td></tr>
		<tr><td class="l"><?=ROOT_PAYER?></td><td><? echo $row['payer'] ?></td></tr>
		<tr><td class="l"><?=ROOT_PAYER_ID?></td><td><? echo $row['payer_id'] ?></td></tr>
		<tr><td class="l"><?=ROOT_PAYMENT_REF_NO?></td><td><? echo $row['payment_ref_no'] ?></td></tr>
		
		<? if(! is_null($row['receipt_doc'])){ ?>
		<tr><td class="l"><?=ROOT_RECEIPT?></td><td><a href="../upload/<?=$row['receipt_doc']?>" target="_blank"><img src="../upload/<?=$row['receipt_doc']?>" height="80" /></a></td></tr>
		<? }} ?>
		<tr><td class="l"><?=ROOT_SHIPPING_METHOD?></td><td><? echo $shipment_method_name ?></td></tr>
		<tr><td class="l"><?=ROOT_SHIPPING_FEE?></td><td><? echo $currency_code.' '.$row['shipment_cost'] ?></td></tr>
		<tr><td class="l"><?=ROOT_ORDER_DISPATCH_TIME?></td><td><? echo $h->text('shipped_time', $row["shipped_time"], 'g') ?> &nbsp; <?=ROOT_EXAMPLE?>: 2012-9-8 9:41:43</td></tr>
		<tr><td class="l"><?=ROOT_SHIPMENT_COMPANY?></td><td><? echo $h->select('express', $row["express"], $arr_express, 'id', 'name_'.$lang, 'g') ?></td></tr>
		<tr><td class="l"><?=ROOT_TRACKING_NUMBER?></td><td><? echo $h->text('shipment_tracking_no', $row["shipment_tracking_no"], 'g') ?></td></tr>
		<tr><td class="l"><?=ROOT_ORDER_STATUS?></td><td><? echo $h->select('order_status', $row["order_status"], $status, 'id', 'name_'.$lang, 'g') ?></td></tr>
		<tr><td class="l"><?=ROOT_HANDLING_REMARKS?></td><td><? echo $h->text('operator_remark', $row["operator_remark"], 'g'); ?></td></tr>
		<tr><td class="l">&nbsp;</td><td><br><? echo $h->submit('save', '&nbsp; '.ROOT_HANDLE_ORDER.' &nbsp;', $iseditmode==1?' button':'hide') ?>&nbsp; <a onClick="history.go(-1)">[ <?=ROOT_CANCEL?> ]</a><br>
		</td></tr>
	</table>
    <? } ?>
	<? function show_boxes($result){ 
		global $page, $pages, $baseurl, $cate, $cateid, $s, $gee, $url, $sales_order_detail, $product, $user, $lang, $country, $code_array, $arrcurrency, $customer, $filter, $h,$payment_method;
		// 构造收款方式数组 arr_payment
		$tem=$payment_method->get_rows(32);
		$arr_payment=array();
		foreach($tem as $val){
			$arr_payment[$val['id']]=$val;
		}
		$str='<table width="99%" class="mlist"><tr>';  // 搜索
		$str.='<td><form action="'.$url.'.php" method="get"><input placeholder="'.ROOT_SEARCH_BY_ORDER_REFERENCE_CUSTOMER_MOBILE.'" name="s" class="g" value="'.$s.'" /> &nbsp; <input class="button_blue" type="submit" value=" '.ROOT_SEARCH.' " /></form></td>';
		$str.='<td '.(($s!='')?"class=\"nada\"":"").' align="right"><form action="'.$url.'.php" method="get">'.$h->select('filter', $filter, $code_array['order_status'], 'id', 'name_'.$lang, 'g', 'this.form.submit()').'</form></td>';
		$str.='</tr></table>';
		$str.= '<table width="99%" cellspacing="0" cellpadding="3" class="mlist" id="picbox"><tr class="th"><td><strong>#</strong></td><td><strong>'.ROOT_ORDER_REFERENCE_NUMBER.'</strong></td><td><strong>'.ROOT_RECEIVER.'</strong></td><td><strong>'.ROOT_PRODUCT.'</strong></td><td><strong>'.ROOT_AMOUNT.'</strong></td><td><strong>'.ROOT_PAYMENT_METHOD.'</strong></td><td><strong>'.ROOT_ORDER_STATUS.'</strong></td><td><strong>'.ROOT_ORDER_TIME.'</strong></td>
		<td><a class="nada" href="'.$url.'.php?a=add">[ '.ROOT_ADD.' ]</a></td></tr>';
		$status=$code_array['order_status'];
		$count=1;
    	foreach($result as $row)
		{
			$tem=$sales_order_detail->get_rows(64,'sales_order_id',$row['id']);
			$iteming='';
			foreach( $tem as $r ){
				$tempro=$product->get_row($r['product_id']);
				$sku=$tempro['sku'];
				$iteming.=$sku.' * '.$r['quantity'];
				$iteming.='<br />';
			}
			$cstatus=$status[$row['order_status']]['name_'.$lang];
			$customer_id=$row['customer_id'];
			if($customer_id==0) $customer_name=ROOT_GUEST_ACCOUNT;
			else {
				$customer_array=$customer->get_row($customer_id);
				$customer_name=$customer_array['email'];
			}
			//$country_name=$country->get_name($row['country'],$lang);
			$currency_code=$arrcurrency[$row['currency_id']]['code'];

			if($row['payment_method_id']==0) $payment_method_name='-';
			else $payment_method_name=$arr_payment[$row['payment_method_id']]['name_'.$lang];

			$id=$row['id'];
      		$str.='<tr><td>'.$id.'.</td><td><a href="'.$url.'.php?do=update&id='.$id.(($filter=="")?"":"&filter=".$filter).'">'.decode($row['ref_no']).'</a></td><td>'.decode($row['contact_name']).'</td><td>';
			$str.=$iteming.'</td><td>'.$currency_code.' '.($row['total_price'] + $row['wallet_amount']).'</td><td>'.$payment_method_name.'</td><td>'.$cstatus.'</td><td>'.$row['created_time'].'</td><td><a href="'.$url.'.php?do=update&id='.$id.(($filter=="")?"":"&filter=".$filter).'">'.ROOT_HANDLE.'</a></td></tr>';
			$count++;
		}
		$str.= "</table>";
		if($count==1) $str.= "<br>".ROOT_NO_DATA."!";
		echo $str;
		echo echo_page_raw($page, $pages, $url.'.php?filter='.$filter.'&page=');
     } ?>
 <br class="clear" />
		</div>
             <br class="clear" />
	</div>
</body>
</html>